package com.smart.six.editor.customize;

import java.beans.PropertyEditorSupport;

/**
 * 自定义的属性编辑器
 *
 * @author junrui.wang
 * @create 2018/7/9
 */
public class CarEditor extends PropertyEditorSupport {

    //重写setAsText方法,解析text生成Car对象
    public void setAsText(String text){
        if(text == null && text.indexOf(",") == -1){
            throw new IllegalArgumentException("设置的字符串格式不正确");
        }

        String[] infos = text.split(",");
        Car car = new Car();
        car.setBrand(infos[0]);
        car.setColor(infos[1]);
        car.setMaxSpeed(Integer.parseInt(infos[2]));
        car.setPrice(Long.parseLong(infos[3]));

        //调用父类的setValue()方法设置转换后的属性对象
        setValue(car);
    }

}
